---
apiVersion: batch/v1
kind: Job
metadata:
  name: plugin-db-updater-job
  labels:
    jobgroup: plugin-db-updater
spec:
  ttlSecondsAfterFinished: 10
  template:
    metadata:
      name: plugin-db-updater-job
      labels:
        jobgroup: plugin-db-updater
    spec:
      initContainers:
      - name: postgres-wait
        image: postgres:14-alpine@sha256:446abaf8831c54f57212c0ae52f5df84e69eeb2767e2376d07bed9c9742b1243
        # yamllint disable rule:indentation
        command: ['sh', '-c',
          'until pg_isready -h ${PL_POSTGRES_HOSTNAME} -p ${PL_POSTGRES_PORT}; do
            echo "waiting for postgres";
            sleep 2;
          done;']
        # yamllint enable rule:indentation
        envFrom:
        - configMapRef:
            name: pl-db-config
      containers:
      - name: updater
        image: cloud-plugin-load_db:latest
        envFrom:
        - configMapRef:
            name: pl-db-config
        - configMapRef:
            name: pl-domain-config
        - configMapRef:
            name: pl-tls-config
        volumeMounts:
        - name: certs
          mountPath: /certs
        env:
        - name: PL_POSTGRES_USERNAME
          valueFrom:
            secretKeyRef:
              name: pl-db-secrets
              key: PL_POSTGRES_USERNAME
        - name: PL_POSTGRES_PASSWORD
          valueFrom:
            secretKeyRef:
              name: pl-db-secrets
              key: PL_POSTGRES_PASSWORD
        - name: PL_JWT_SIGNING_KEY
          valueFrom:
            secretKeyRef:
              name: cloud-auth-secrets
              key: jwt-signing-key
        - name: PL_PLUGIN_SERVICE
          valueFrom:
            configMapKeyRef:
              name: pl-service-config
              key: PL_PLUGIN_SERVICE
        - name: PL_PLUGIN_REPO
          value: "pixie-io/pixie-plugin"
      restartPolicy: Never
      volumes:
      - name: pl-db-secrets
        secret:
          secretName: pl-db-secrets
      - name: certs
        secret:
          secretName: service-tls-certs
  backoffLimit: 1
  parallelism: 1
  completions: 1
